2 class PNGHandlerTest
extends MediaWikiTestCase
{
4 protected function setUp() {
7 $this->filePath
= __DIR__
. '/../../data/media';
8 $this->backend
= new FSFileBackend( array(
9 'name' => 'localtesting',
10 'lockManager' => 'nullLockManager',
11 'containerPaths' => array( 'data' => $this->filePath
)
13 $this->repo
= new FSRepo( array(
15 'url' => 'http://localhost/thumbtest',
16 'backend' => $this->backend
18 $this->handler
= new PNGHandler();
21 public function testInvalidFile() {
22 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
23 $this->assertEquals( PNGHandler
::BROKEN_FILE
, $res );
26 * @param $filename String basename of the file to check
27 * @param $expected boolean Expected result.
28 * @dataProvider provideIsAnimated
30 public function testIsAnimanted( $filename, $expected ) {
31 $file = $this->dataFile( $filename, 'image/png' );
32 $actual = $this->handler
->isAnimatedImage( $file );
33 $this->assertEquals( $expected, $actual );
35 public static function provideIsAnimated() {
37 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
38 array( '1bit-png.png', false ),
43 * @param $filename String
44 * @param $expected Integer Total image area
45 * @dataProvider provideGetImageArea
47 public function testGetImageArea( $filename, $expected ) {
48 $file = $this->dataFile($filename, 'image/png' );
49 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
50 $this->assertEquals( $expected, $actual );
52 public static function provideGetImageArea() {
54 array( '1bit-png.png', 2500 ),
55 array( 'greyscale-png.png', 2500 ),
56 array( 'Png-native-test.png', 126000 ),
57 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
62 * @param $metadata String Serialized metadata
63 * @param $expected Integer One of the class constants of PNGHandler
64 * @dataProvider provideIsMetadataValid
66 public function testIsMetadataValid( $metadata, $expected ) {
67 $actual = $this->handler
->isMetadataValid( null, $metadata );
68 $this->assertEquals( $expected, $actual );
70 public static function provideIsMetadataValid() {
72 array( PNGHandler
::BROKEN_FILE
, PNGHandler
::METADATA_GOOD
),
73 array( '', PNGHandler
::METADATA_BAD
),
74 array( null, PNGHandler
::METADATA_BAD
),
75 array( 'Something invalid!', PNGHandler
::METADATA_BAD
),
76 array( 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}', PNGHandler
::METADATA_GOOD
),
81 * @param $filename String
82 * @param $expected String Serialized array
83 * @dataProvider provideGetMetadata
85 public function testGetMetadata( $filename, $expected ) {
86 $file = $this->dataFile( $filename, 'image/png' );
87 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
88 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
89 $this->assertEquals( ( $expected ), ( $actual ) );
91 public static function provideGetMetadata() {
93 array( 'rgb-na-png.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}' ),
94 array( 'xmp.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:1;s:9:"colorType";s:14:"index-coloured";s:8:"metadata";a:2:{s:12:"SerialNumber";s:9:"123456789";s:15:"_MW_PNG_VERSION";i:1;}}' ),
98 private function dataFile( $name, $type ) {
99 return new UnregisteredLocalFile( false, $this->repo
,
100 "mwstore://localtesting/data/$name", $type );